package com.lt.test.provider.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.lt.test.api.CountService;
import com.lt.test.provider.mapper.CountMapper;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * 统计订单数据相关Servicer
 * 创建人：lt
 * 创建时间：15:10 2018/1/25
 */
@Service(version = "1.0.0")
public class CountServiceImpl implements CountService {
    @Resource
    CountMapper countMapper;

    public List<Map<String, Object>> getScanCode(Map<String, Object> params) {
        String turnCreateDate = params.get("turnCreateDate") == null ? "" : params.get("turnCreateDate").toString();
        String bindCreateDate = params.get("turnCreateDate") == null ? "" : params.get("turnCreateDate").toString();
        if (turnCreateDate.equals("") || bindCreateDate.equals("")){
            SimpleDateFormat simpleDate = new SimpleDateFormat("YYYY-MM-dd");
            String data = simpleDate.format(new Date());
            params.put("turnCreateDate", data);
            params.put("bindCreateDate", data);
        }
        System.out.println("===========>"+params);
        return countMapper.selectScanCode(params);
    }

    public List<Map<String, Object>> getOrder(Map<String, Object> params) {
        String turnCreateDate = params.get("turnCreateDate") == null ? "" : params.get("turnCreateDate").toString();
        String bindCreateDate = params.get("turnCreateDate") == null ? "" : params.get("turnCreateDate").toString();
        if (turnCreateDate.equals("") || bindCreateDate.equals("")){
            SimpleDateFormat simpleDate = new SimpleDateFormat("YYYY-MM-dd");
            String data = simpleDate.format(new Date());
            params.put("turnCreateDate", data);
            params.put("bindCreateDate", data);
        }
        System.out.println("===========>"+params);
        return countMapper.selectOrder(params);
    }

    @Override
    public List<Map<String, Object>> getOrdeEcror(Map<String, Object> params) {
        String turnCreateDate = params.get("turnCreateDate") == null ? "" : params.get("turnCreateDate").toString();
        String bindCreateDate = params.get("turnCreateDate") == null ? "" : params.get("turnCreateDate").toString();
        if (turnCreateDate.equals("") || bindCreateDate.equals("")){
            SimpleDateFormat simpleDate = new SimpleDateFormat("YYYY-MM-dd");
            String data = simpleDate.format(new Date());
            params.put("turnCreateDate", data);
            params.put("bindCreateDate", data);
        }
        System.out.println("===========>"+params);
        return countMapper.selectOrdeEcror(params);
    }

    @Override
    public List<Map<String, Object>> getWeekList() {
        return countMapper.selectWeekList();
    }

    @Override
    public List<Map<String, Object>> getRecommendOrde(Map<String, Object> params) {
        String yearMonth = params.get("yearMonth") == null ? "" : params.get("yearMonth").toString();
        String week = params.get("week") == null ? "" : params.get("week").toString();
        if (yearMonth.equals("")) {
            SimpleDateFormat simpleDate = new SimpleDateFormat("YYYY-MM-dd");
            yearMonth = simpleDate.format(new Date());
            params.put("yearMonth", yearMonth);
        }
        if (week.equals("")){
            List<Map<String, Object>> week_list = countMapper.selectWeek(params);
            if (week_list.size() > 0){
                Map<String, Object> map = week_list.get(0);
                week = map.get("week") == null ? "" : map.get("week").toString();
                yearMonth = map.get("yearMonth") == null ? "" : map.get("yearMonth").toString();
                params.put("week", week);
                params.put("yearMonth",yearMonth);
            }
        }
        System.out.println("===========>"+params);
        if (!week.equals("")){
            List<Map<String, Object>> list = countMapper.selectRecommendOrde(params);
            return list;
        }
        return null;
    }

    @Override
    public List<Map<String, Object>> getTobaccoOrde(Map<String, Object> params) {

        String beginDate = params.get("beginDate") == null ? "" : params.get("beginDate").toString();
        String endDate = params.get("endDate") == null ? "" : params.get("endDate").toString();
        if (beginDate.equals("") && endDate.equals("")) {
            SimpleDateFormat simpleDate = new SimpleDateFormat("YYYYMMdd");
            beginDate = simpleDate.format(new Date());
            endDate = beginDate;
            params.put("beginDate", beginDate);
            params.put("endDate", endDate);
        }
        System.out.println("===========>"+params);
        return countMapper.selectTobaccoOrde(params);
    }

    public static void main(String[] sage){
        SimpleDateFormat simpleDate = new SimpleDateFormat("YYYYMMdd");
        String data = simpleDate.format(new Date());
        System.out.println(data);
    }



}
